<template>
  <div class="oauth-qq w-flex-center">
    <a-spin size="large"/>
  </div>
</template>

<script>
import { QueryString } from '@/utils/tool'
export default {
  name: 'OAuthQQ',
  layout: 'OAuth',
  mounted () {
    this.getAccessToken()
  },
  methods: {
    getAccessToken () {
      const { hash } = window.location
      if (hash) {
        const query = QueryString.parse(hash)
        const accessToken = query['#access_token']
        this.$store
          .dispatch('oauth/LOGIN', accessToken)
          .then(() => {
            this.toOAuthPage('登录成功', true)
          })
          .catch(() => {
            this.toOAuthPage('登录失败', false)
          })
      }
    },
    toOAuthPage (msg, success) {
      this.$message[success ? 'success' : 'error'](msg)
      const webBack = sessionStorage.getItem(process.env.OAUTH_WEB_BACK_URL_KEY) || ''
      sessionStorage.removeItem(process.env.OAUTH_WEB_BACK_URL_KEY)
      this.$router.replace({
        path: '/OAuth',
        query: {
          webBack
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
.oauth-qq {
  height: 100vh;
}
</style>
